<?php
$docRoot = $_SERVER ['DOCUMENT_ROOT'] . '/' . strtok ( $_SERVER ['PHP_SELF'], '/' );
include_once ($docRoot . "/application/service/db/DBConnectionManager.php");
?>

<?php

class TeamLoaderDAO {
	
	public function addTeam($teamId, $teamName, $rostersUrl, $statsUrl) {
		$connection = DBConnectionManager::getDBConnecion ();
		$sql = "insert into `team` set `team_id`='$teamId',`team_name`='$teamName',`rosters_feed`='$rostersUrl',`stats_feed`='$statsUrl'";
		mysql_query ( $sql ) or die ( "Unable to add team details " . mysql_error () );
		mysql_close ( $connection );
	}
	
	public function addPlayers($players, $teamId) {
		//loop for each player and insert into db
		$connection = DBConnectionManager::getDBConnecion ();
		foreach ( $players as $player ) {
		    $playerName = $player["name"];
		    $playerId = $player["id"];		    
		    $query = "insert into `player` set `player_id`='$playerId',`player_name`='$playerName',`team_id`='$teamId' ";
		    mysql_query ( $query ) or die ( "Unable to add player details " . mysql_error () );
		}
		mysql_close ( $connection );
	}
}

?>